import { useSelector, useDispatch } from 'react-redux';

function Child() {
  // 创建dispatch
  const dispatch = useDispatch();

  // 从store中选取数据
  const data = useSelector((state) => state.counter);

  // 事件处理函数
  const handleIncrement = () => {
    dispatch({ type: 'increment', payload: 2 });
  };

  return (
    <div>
      <h3>{data}</h3>
      <button onClick={handleIncrement}>+</button>
    </div>
  );
}

export default Child;
